package day03;

import java.util.Arrays;

public class ShuffleArrayReturnNewArray {
	public static void main(String[] args) {

		int[] x = { 2, 8, 10, 12, 33 };
		int [] y = shuffle(x);
		System.out.println("原数组x: "+Arrays.toString(x));
		System.out.println("新数组  : "+Arrays.toString(y));	

	}

	public static int[] shuffle(int[] n) {
		int array[] = new int[n.length];
		for (int k = 0; k < n.length; k++) {
			array[k] = n[k];
		}
		int i, temp;
		int j = 0;
		int length = n.length;
		for (i = 0; i < length; i++) {
			j = (int) (i * Math.random());
			temp = array[i];
			array[i] = array[j];
			array[j] = temp;
		}
		return array;
	}
}
